/**
 * 
 */
package com.nassir.excel.cellwriter;

import org.apache.poi.hssf.usermodel.HSSFCell;

import com.nassir.excel.model.Cell;

/**
 * @author zhangqiulong
 *
 */
public class DefaultCellWriter implements ICellWriter<Object> {

	public boolean accept(String type) {
		return CELL_TYPE_DATE.equals(type);
	}

	public void write(HSSFCell cell, Cell head, Object data) {
	 /*  cell.setCellValue(data);
       HSSFCellStyle cellStyle = cell.getSheet().getWorkbook().createCellStyle(); 
       cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat(head.getFormat())); 
       cell.setCellStyle(cellStyle);*/
	    if(data != null) {
	        if(data instanceof String ){
	            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
	            cell.setCellValue(String.valueOf(data));
	        }
	        else if(data instanceof Boolean ){
	            cell.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
	            cell.setCellValue(Boolean.valueOf(data.toString()));
	        }
	        else{
	            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
	            cell.setCellValue(data.toString());
	        }
		}else {
		    cell.setCellValue("");
		}
		
	}

}
